package cn.dliyy.warehouse.abnormal;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Aspect
public class DaoAop {
	public DaoAop() {

	}

	@Pointcut("execution(* cn.dliyy.warehouse.dao.EntityDao.*(..)) && target(cn.dliyy.warehouse.dao.EntityDao)")
	public void pointcut() {
		System.out.println("--------------aop---");
	}

	// 前置通知 (Before Advice)
	@Before("pointcut() && args(arg, . .)")
	public void beforeExecute(JoinPoint thisJoinPoint, Object arg) {
		System.out.println("连接点类型：" + thisJoinPoint.getKind());
		System.out.println("代理类名："
				+ thisJoinPoint.getSourceLocation().getClass().getName());
		System.out.println("目标类名："
				+ thisJoinPoint.getTarget().getClass().getName());
		System.out.println("目标函数名：" + thisJoinPoint.getSignature().getName());
		System.out.println("参数个数：" + thisJoinPoint.getArgs().length);
		System.out.println("参数值：" + arg);
		System.out.println("Before Advice!");
	}

	// 返回后通知(After returning Advice)
	@AfterReturning(pointcut = "pointcut()", returning = "retVal")
	public void afterExecuet(JoinPoint thisJoinPoint, Object retVal) {
		System.out.println("return " + retVal);
	}

	// 抛出异常后通知(After Throwing Advice)
	@AfterThrowing(pointcut = "pointcut()", throwing = "ex")
	public void afterThrowing(JoinPoint thisJointPoint, Exception ex) {
		System.out.println("Throwing " + ex);
	}

	// 后通知 (After Advice)
	@After("pointcut()")
	public void afterExecute(JoinPoint thisJoinPoint) {
		System.out.print("After Advice!");
	}

	// 环绕通知（Around Advice）
	@Around("pointcut()")
	public Object userOperate(ProceedingJoinPoint thisJoinPoint)
			throws Throwable {
		System.out.println("Around Advice!");
		return thisJoinPoint.proceed();
	}

}
